package main

import (
	"fmt"

	"github.com/user/watch"
)

type listener struct {
}

func (l listener) Listen(old watch.Configuration, new watch.Configuration) {
	if old.GetSectionNum() != new.GetSectionNum() {
		fmt.Println("The file has been changed!")
	} else {
		for keySection, section := range old.GetSection() {
			if !new.ExistSection(keySection) {
				fmt.Println("The file has been changed!")
				return
			} else {
				NewSection := new.GetKey(keySection)
				if section.GetKeyNum() != NewSection.GetKeyNum() {
					fmt.Println("The file has been changed!")
					return
				} else {
					for key, value := range section.GetKey() {
						if !NewSection.ExistKey(key) || value != NewSection.GetValue(key) {
							fmt.Println("The file has been changed!")
							return
						}
					}
				}
			}
		}
	}
}

func main() {
	_, err := watch.Watch("test.ini", listener{})

	if err != nil {
		fmt.Println(err)
	}
}
